home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / etc / init.d / hplip < prev    next >
Encoding:
Text File  |  2007-04-04  |  4.4 KB  |  217 lines

  1. #! /bin/sh
  2. # hplip    initscript for the HP Linux Printing and Imaging System
  3. # Copyright (c) 2004-2006 by Henrique de Moraes Holschuh <hmh@debian.org>
  4. # Distributed under the GPLv2 or newer
  5. #
  6. # $Id: hplip.init,v 1.16 2006/10/26 15:39:43 hmh Exp $
  7.  
  8. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  9. DESC="HP Linux Printing and Imaging System"
  10.  
  11. # For manual setuid/gid
  12. SUID_USER=hplip
  13. SGID_GROUP=lp
  14.  
  15. DAEMON1=/usr/sbin/hpiod
  16. NAME1=hpiod
  17. PROCNAME1=$NAME1
  18. PIDFILE1=/var/run/hplip/hpiod.pid
  19.  
  20. DAEMON2=/usr/sbin/hpssd
  21. NAME2=hpssd
  22. PROCNAME2=python
  23. PIDFILE2=/var/run/hplip/hpssd.pid
  24. FILES2="/var/run/hplip/hpssd.pid /var/run/hplip/hpssd.port"
  25.  
  26. HPIODOPTIONS=
  27. HPSSDOPTIONS=
  28. RUN_HPIOD_AS_ROOT=yes
  29.  
  30. [ -r /etc/default/hplip ] && . /etc/default/hplip
  31.  
  32. case "$RUN_HPLIP" in
  33.        [nN]*) exit 0
  34. esac
  35.  
  36. test -x ${DAEMON1} || exit 0
  37.  
  38. . /lib/lsb/init-functions
  39.  
  40. set -e
  41.  
  42. ###
  43. ### dpkg-statoverride support
  44. ###
  45.  
  46. createdir() {
  47. # $1 = user
  48. # $2 = group
  49. # $3 = permissions (octal)
  50. # $4 = path to directory
  51.     [ -d "$4" ] || mkdir -p -m "$3" "$4"
  52.     chown -R -H --preserve-root "$1:$2" "$4"
  53.     chmod "$3" "$4"
  54. }
  55.  
  56. fixdirs() {
  57.         dir=$(dpkg-statoverride --list /var/run/hplip) || {
  58.         echo "You are missing a dpkg-statoverride on /var/run/hplip.  Fix it, otherwise you risk silent breakage on upgrades.  If you have no idea what to do, just reinstall hplip and it will fix itself." >&2
  59.         exit 1
  60.     }
  61.     [ -z "$dir" ] || createdir $dir
  62.     # clear exit status
  63.     :
  64. }
  65.  
  66. ###
  67.  
  68. DIDSOMETHING=0
  69. reload_cups() {
  70.     if [ ${DIDSOMETHING} -ne 0 ] ; then
  71.         # Tell cupsys that we (may) have a new ative backend
  72.         # be silent about it to avoid unneeded hassles duing
  73.         # shutdowns -- it is not like we care if this suceeds or
  74.         # not...
  75.         invoke-rc.d --quiet cupsys reload >/dev/null 2>&1 || true
  76.     fi
  77.     return 0
  78. }
  79.  
  80. start_daemon() {
  81.     DAEMON="$1"
  82.     PIDFILE="$2"
  83.     NAME="$3"
  84.     PROCNAME="$4"
  85.     SSDOPT="$5"
  86.     DAEMONOPT="$6"
  87.  
  88.     START="--start --quiet --pidfile ${PIDFILE} --startas ${DAEMON} --name ${PROCNAME} ${SSDOPT}"
  89.     [ -n "${DAEMONOPT}" ] && START="${START} -- ${DAEMONOPT}"
  90.     if start-stop-daemon ${START} >/dev/null 2>&1 ; then
  91.         #success
  92.         DIDSOMETHING=1
  93.     else
  94.         if start-stop-daemon --test ${START} >/dev/null 2>&1; then
  95.             #failed
  96.             return 1
  97.         else
  98.             #already running
  99.             return 0
  100.         fi
  101.     fi
  102.     return 0
  103. }
  104.  
  105. stop_daemon() {
  106.     DAEMON="$1"
  107.     PIDFILE="$2"
  108.     NAME="$3"
  109.     PROCNAME="$4"
  110.  
  111.     # yes, it is --start. go read the manpage
  112.     STOP="--start --quiet --pidfile ${PIDFILE} --startas ${DAEMON} --name ${PROCNAME}"
  113.  
  114.     if start-stop-daemon --stop --quiet --pidfile ${PIDFILE} \
  115.         --retry 10 --name ${PROCNAME} \
  116.         >/dev/null 2>&1 ; then
  117.             # success
  118.             DIDSOMETHING=1
  119.             # FIXME: change hpiod so that this is not necessary
  120.             sleep 2
  121.     else
  122.         if start-stop-daemon --test ${STOP} >/dev/null 2>&1; then
  123.             # already stopped
  124.             return 0
  125.         else
  126.             # failed, still running
  127.             return 1
  128.         fi
  129.     fi
  130.     return 0
  131. }
  132.  
  133. do_start () {
  134.     log_daemon_msg "Starting ${DESC}"
  135.     fixdirs
  136.     case "$RUN_HPIOD_AS_ROOT" in
  137.            [nN]*) HPIOD_SSDOPT="--chuid ${SUID_USER} --group ${SGID_GROUP}";;
  138.     *)     HPIOD_SSDOPT=""
  139.     esac
  140.     log_progress_msg "${NAME1}"
  141.     if start_daemon "${DAEMON1}" "${PIDFILE1}" "${NAME1}" \
  142.         "${PROCNAME1}" "${HPIOD_SSDOPT}" \
  143.         "${HPIODOPTIONS}" && \
  144.        {
  145.          log_progress_msg "${NAME2}"
  146.          for i in ${FILES2} ; do
  147.              [ -f "$i" ] && chown "${SUID_USER}:${SGID_GROUP}" "$i"
  148.         :
  149.          done
  150.          start_daemon "${DAEMON2}" "${PIDFILE2}" "${NAME2}" \
  151.            "${PROCNAME2}" "--chuid ${SUID_USER} --group ${SGID_GROUP}" \
  152.         "${HPSSDOPTIONS}"
  153.        } ; then
  154.        log_end_msg 0
  155.        reload_cups
  156.     else
  157.        log_end_msg 1 || true
  158.        return 1
  159.     fi
  160.     return 0
  161. }
  162.  
  163. do_stop () {
  164.     log_daemon_msg "Stopping ${DESC}"
  165.         log_progress_msg "${NAME1}"
  166.     if stop_daemon "${DAEMON2}" "${PIDFILE2}" "${NAME2}" \
  167.             "${PROCNAME2}"
  168.     then
  169.        log_progress_msg "${NAME2}"
  170.        stop_daemon "${DAEMON1}" "${PIDFILE1}" "${NAME1}" \
  171.                "${PROCNAME1}" && {
  172.          log_end_msg 0
  173.          return 0
  174.        }
  175.        log_end_msg 1 || true
  176.        return 1
  177.     else
  178.        log_end_msg 1 || true
  179.        log_daemon_msg "Stopping ${DESC}"
  180.        log_progress_msg "${NAME2}"
  181.        if stop_daemon "${DAEMON1}" "${PIDFILE1}" "${NAME1}" \
  182.                "${PROCNAME1}" ;
  183.        then
  184.          log_end_msg 1 || true
  185.        else
  186.          log_end_msg 0
  187.        fi
  188.        log_failure_msg "Failed to stop all components of ${DESC}."
  189.        return 1
  190.     fi
  191. }
  192.  
  193. case "$1" in
  194.   start)
  195.       set -e
  196.       do_start
  197.       exit 0
  198.     ;;
  199.   stop)
  200.       set -e
  201.       do_stop
  202.       exit 0
  203.     ;;
  204.   restart|force-reload)
  205.       do_stop || true
  206.     set -e
  207.     do_start
  208.     exit 0
  209.     ;;
  210.   *)
  211.     log_warning_msg "Usage: $0 {start|stop|restart|force-reload}"
  212.     exit 1
  213.     ;;
  214. esac
  215.  
  216. exit 0
  217.